<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class login extends CI_Controller {

    function __construct(){
        parent::__construct();
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("If-Modified-Since: Mon, 22 Jan 2008 00:00:00 GMT");
		header("Cache-Control: no-store, no-cache, must-revalidate");
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Cache-Control: private");
		header("Pragma: no-cache");
		$this->load->model('mlogin');
		$this->host = $this->config->item('base_url');
	}

	public function index(){
		$data['pesan'] = "";
		$this->load->view('login',$data);
	}
	
	function loginuser(){
		$this->load->library('encrypt');
		$user = $this->input->post('username');
		$pass = $this->input->post('password');
		$acakpassword = $user.$pass;
		
		//echo $this->encrypt->encode($acakpassword); exit;
		
		if(!$user or !$pass){
			$data['pesan'] = "<font color='red'>isi username dan password dengan benar!</font>";
			$this->load->view('login',$data);
			return;
		}
		
		$data = $this->mlogin->login($user);
		
		if($data){			
			$password_database_asli = $this->encrypt->decode($data['password']);
			$password_inputan = $acakpassword;
			
			if($password_database_asli == $password_inputan){
				$this->session->set_userdata('sisfodealer', base64_encode(serialize($data)));
				header("Location: " . $this->host."home");
			}else{
				$data['pesan'] = "<font color='red'>password anda salah!</font>";
				$this->load->view('login',$data);
				return;
			}
		}else{
			$data['pesan'] = "<font color='red'>akun anda tidak ditemukan!</font>";
			$this->load->view('login',$data);
			return;
		}

	}
	
	function logout(){
		$this->session->unset_userdata('sisfodealer', 'limit');
		$this->session->sess_destroy();
		header("Location: " . $this->host);
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */